Ext.namespace('VAS');



VAS.DynamicNewFormWindow = function($config) {
	var _this = this;
	_this.dynamicFormPanel = new Ext.ux.DynamicItems({fieldSet:$config.data.fieldSet,
	buttons: [{
            text: 'Save',
            handler:function(){
            	if(_this.dynamicFormPanel.getForm().isValid()){              
            	
            			_this.dynamicFormPanel.getForm().submit({
		              url:$config.data.action,
					  waitTitle: '正在提交',
		              waitMsg: '正在向服务器发送请求',
		              clientValidation: true,
					  success :function(form,action){
							Ext.Msg.alert('提示','提交保存成功!',function(){ 
								_this.dynamicFormPanel.getForm().reset();
							});
							
					  },
					  failure :function(form,action){
							if(action.failureType == Ext.form.Action.CLIENT_INVALID){
								Ext.Msg.alert('提示','输入的信息不符合规格，请按照提示重新输入！');
							}else{
								alertFailure(action.result.data);
							}
					 }		
					 ,params:{formId:$config.data.fieldSet.id}
		        });
            	
            	}else{
            		Ext.Msg.alert('提示','请填入必填项');
            	}
            }
        },{
            text: 'Cancel'
           , handler:function(){
            	_this.close();
            }
        }]})

	var thisConfig = {
		closeAction : 'close',
		alwaysOnTop : true,
		modal : true,		
		items :_this.dynamicFormPanel

	};
	var _config = $config || {};

	Ext.apply(_this, Ext.apply(thisConfig, _config));
	VAS.DynamicNewFormWindow.superclass.constructor.call(_this);

};

Ext.extend(VAS.DynamicNewFormWindow,Ext.Window,{
manager:wgroup});
Ext.reg('dynamicNewForm-win',VAS.DynamicNewFormWindow);



